package org.hq.web.security;

import org.hq.web.sql.pojo.WebUser;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

/**
 * 自定义登录系统用户
 */
public class LoginUser  implements UserDetails {
    private WebUser user;

    public LoginUser(WebUser user) {
        this.user = user;
    }

    public WebUser getUser() {
        return user;
    }

    /**
     * 权限用户数组
     * @return
     */
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        //用户配置
        return AuthorityUtils.commaSeparatedStringToAuthorityList(user.getGranted());
    }

    @Override
    public String getPassword() {
        return user.getPassword();
    }

    @Override
    public String getUsername() {
        return user.getUserid();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
